package com.sykj.cloud.mq.demo.consumer;

import com.sykj.cloud.mq.demo.Constant;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.common.message.MessageExt;

import java.util.List;

import static com.sykj.cloud.mq.demo.Constant.*;

/**
 * @author Mr.will
 * @date 2021/3/4 11:15
 * @Desc 消费者DEMO
 */
public class Consumer {

    public static void main(String[] args) throws Exception {
        DefaultMQPushConsumer consumer=new DefaultMQPushConsumer("group01");
        consumer.setNamesrvAddr(SERVER_URL);
//        consumer.subscribe(TOPIC_1,TAG_1);
//        consumer.subscribe(TOPIC_1,TAG_1);
        consumer.subscribe(TOPIC_3,TAG_3);
        consumer.registerMessageListener(new MessageListenerConcurrently() {
            @Override
            public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
                for (MessageExt msg : msgs) {
                    System.out.println("接受消息"+ new String(msg.getBody()));
                }
                return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
            }
        });

        consumer.start();





    }


}
